<?php

/**
 * 入口文件
 * @author 徐亚坤 hdyakun@sina.com
 */

define('ENVIRONMENT', 'development');

if(defined('ENVIRONMENT')) {
    switch(ENVIRONMENT) {
        case 'development':
            error_reporting(E_ALL);
        break;
    
        case 'testing':

        case 'production':
            error_reporting(0);
        break;

        default:
            exit('The application environment is not set correctly.');
    }
}

// 目录间隔符
define("DS", DIRECTORY_SEPARATOR);

// 根目录
define('BASEPATH', __DIR__);

$application_folder = 'app';
$application_view_folder = 'views';

// 应用目录
define('APP_PATH', BASEPATH.DS.$application_folder);
// 应用视图目录
define('APP_VIEW_PATH', APP_PATH.DS.$application_view_folder.DS);

// 加载文件函数
function import($filepath, $base = null, $key = null)
{
    static $paths;
    $keypath = $key ? $key.$filepath : $filepath;

    if(!isset($paths[$keypath])) {
        if(is_null($base)) {
            $base = BASEPATH.'/';
        }
        $parts = explode('.', $filepath);
        array_pop($parts);
        $path = str_replace('.', DS, $filepath);
        $paths[$keypath] = require $base.$path.'.php';
    }
    return $paths[$keypath];
}

// bootstrap
require './bootstrap/autoload.php';
require './bootstrap/start.php';
// events
require APP_PATH.'/events.php';
// Routes
require APP_PATH.'/routes.php';